package model.container;

/**
 * 
 * @author Wim A container class that can be used to instantiate a given amount
 *         of Teacher instances that can be used for testing purposes.
 * 
 */

import java.util.ArrayList;

import model.Teacher;
import model.generator.TeacherGenerator;
//import model.generator.CourseGenerator;
// model.generator.TeacherGenerator;

public class TeacherContainer {

	private static TeacherContainer teacherContainer;

	private ArrayList<Teacher> teachers;

	/* Make sure the class cannot be instantiated */
	private TeacherContainer() {
		this.teachers = new ArrayList<Teacher>();

	}

	public void generateData() {
		try {
			teachers = TeacherGenerator.generateTeachers(10);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/** Constructs a new teacher container object if none exists */
	public static synchronized TeacherContainer getInstance() {
		if (teacherContainer == null) {
			teacherContainer = new TeacherContainer();
		}
		return teacherContainer;
	}

	/** Return the list of teachers */
	public ArrayList<Teacher> getTeachers() {
		return teachers;
	}

	/** Set the list of teachers */
	public void setTeachers(ArrayList<Teacher> teachers) {
		this.teachers = teachers;
	}

	/** ???????????? */
	public void finishInitialisation() {
		TeacherGenerator.finishTeacherInitialisation();
	}

	/** Clear the container */
	public void clear() {
		teachers.clear();
	}

	/** Add a teacher to the container */
	public void addTeacher(Teacher teacher) {
		teachers.add(teacher);
	}

	/** Remove a teacher from the container */
	public void removeTeacher(Teacher teacher) {
		this.teachers.remove(teacher);
	}

	public int getTeacherCount() {
		return teachers.size();
	}

	/** Prints all teachers in the container */
	public String printAllTeachers() {
		String s = new String();
		for (Teacher teacher : teachers) {
			s += teacher.toString() + "\n";
		}
		return s;
	}

	/** Searches for a teacher with a specified ID */
	public Teacher getTeacherByID(String id) {
		for (Teacher teacher : this.teachers) {
			if (teacher.getTeacherCode().equals(id)) {
				return teacher;
			}
		}
		return null;
	}
}
